package com.kingint.web.portal.serve.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.bas.entity.Scheduling;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.admin.base.service.SchedulingService;
import com.kingint.web.admin.base.service.UmsClockService;
import com.kingint.web.sys.service.UmsAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @描述：用户打卡记录关联表控制类
 * @作者: wxh
 * @日期: 2021-01-23
 */
@RestController
@RequestMapping("/umsClock")
@Api(value = "UmsClockController", description = "用户打卡记录关联表")
@CrossOrigin
public class ClocksController {


    @Autowired
    public UmsClockService umsClockService;

    @Autowired
    private UmsAdminService umsAdminService;

    @Autowired
    private SchedulingService schedulingService;

    /**
     *
     * @param longitude :经度
     * @param latitude ：纬度
     * @return
     */
    @ApiOperation(value = "用户上下班打卡")
    @GetMapping("/clocksInOrOut")
    public Object clocksInOrOut(@RequestParam("longitude") Double longitude,@RequestParam("latitude") Double latitude) {
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if (currentMember == null) {
            return K.error().message("用户不存在");
        }
        return umsClockService.umslocksIn(longitude,latitude,currentMember);
    }

    @ApiOperation(value = "获取用户上班状态")
    @GetMapping("/getWorkStatus")
    public Object getWorkStatus(){
        return umsClockService.WorkStatus();
    }

    @ApiOperation(value = "获取酒店下的所有排班规则")
    @GetMapping("getlistall")
    public Object getlistall(){
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if(StringUtils.isEmpty(currentMember)){
            return K.error();
        }
        QueryWrapper<Scheduling> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("hotel_id",currentMember.getHotelId());
        List<Scheduling> list = schedulingService.list(queryWrapper);
        if(list.size()>0){
            return K.ok().data(list);
        }else{
            return K.error().message("还没有设置排班规则");
        }

    }
}
